// cc.Class({
//     extends: cc.Component,
//     properties: {
//         node_boss: cc.Node,
//         clear_count: 0,
//         node_m_node: cc.Node
//     },
//     handle_event_scrollview_touch_end: function (e) {
//         this.node_scroll_view_content.y += e.getDelta().y;
//         if (this.node_scroll_view_content.y < -400 - (this.node_scroll_view_content.height - 400)) {
//             this.node_scroll_view_content.y = -400 - (this.node_scroll_view_content.height - 400);
//         }
//         if (this.node_scroll_view_content.y > -400) {
//             this.node_scroll_view_content.y = -400;
//         }
//     },
//     onLoad: function () {
//         var e = this;
//         this.node_m_node = cc.find("node/node", this.node);
//         this.node_scroll_view_content = cc.find("node/node/ScrollView/view/content", this.node);
//         this.scrollView = cc.find("node/node/ScrollView", this.node);
//         this.scrollView.on(cc.Node.EventType.TOUCH_MOVE, function (t) {
//             e.node_scroll_view_content.y += t.getDelta().y;
//         });
//         this.scrollView.on(cc.Node.EventType.TOUCH_END, function (t) {
//             e.handle_event_scrollview_touch_end(t);
//         });
//         this.scrollView.on(cc.Node.EventType.TOUCH_CANCEL, function (t) {
//             e.handle_event_scrollview_touch_end(t);
//         });
//         this.scrollView._touchListener.setSwallowTouches(!1);
//         this.titleArray = [];
//         cc.winSize;
//         var t = this.node_boss.addComponent(cc.Widget);
//         t.left = 0;
//         t.top = 0;
//         t.isAlignTop = !0;
//         t.isAlignLeft = !0;
//     },
//     start: function () {
//         this.touchNum = 0;
//         this.time = parseInt(getTime() / 1e3);
//         this.node_boss.on(
//             cc.Node.EventType.TOUCH_START,
//             function () {
//                 if (this.node_boss._touchListener) {
//                     this.node_boss._touchListener.setSwallowTouches(!1);
//                 }
//                 this.touchNum++;
//                 var e = parseInt(getTime() / 1e3);
//                 e - this.time < 10
//                     ? this.touchNum >= 7 &&
//                       (cc.systemEvent.emit("lieyou_openBossKey"),
//                       (al_show_debug = !0),
//                       (cc.find("node/node/version", this.node).getComponent(cc.Label).string =
//                           " " + _sdk_version + "/" + ailin_sdk_manager.instance.getVersion()),
//                       (this.touchNum = 0),
//                       (this.time = e),
//                       (cc.find("node/node", this.node).active = !0),
//                       ailin_sdk_manager.setClipboardData(
//                           JSON.stringify({
//                               uuid: AL_User_Info.huoqu_open_id(),
//                               openid: AL_User_Info.huoqu_open_id()
//                           })
//                       ),
//                       ailin_sdk_manager.showToast("成功复制uuid"),
//                       ailin_sdk_manager.addBossTitle("后台：" + al_login_url),
//                       (ailin_sdk_manager.instance.xiangmu_ceshi_kaiguan = !1))
//                     : ((this.touchNum = 0), (this.time = e));
//             }.bind(this)
//         );
//     },
//     tianjiaTitle: function (e, t) {
//         if (void 0 === e) {
//             e = "";
//         }
//         if (cc.find("node/node", this.node).active) {
//             var o = this.node_scroll_view_content;
//             var i = new cc.Node();
//             i.width = 300;
//             i.anchorX = 0;
//             i.anchorY = 0;
//             var n = i.addComponent(cc.Label);
//             n.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
//             n.string = e;
//             n.fontSize = 25;
//             o.addChild(i);
//             i.color = t;
//         }
//     },
//     guanbiHuidiao: function () {
//         cc.find("node/node", this.node).active = !1;
//     },
//     jianchaHuidiao: function () {
//         var e = ailin_sdk_manager.instance._lieyou_online_param;
//         if (e) {
//             e = JSON.stringify(e);
//             AL_Framework_al_interface.xianshi_layer_ceng(e);
//         }
//     },
//     qingchuHuidiao: function () {
//         var e = this;
//         this.clear_count++;
//         setTimeout(function () {
//             e.clear_count--;
//         }, 900);
//         console.log("--------------qingchuHuidiao  clear_count", this.clear_count);
//         this.clear_count >= 6
//             ? ((ailin_sdk_manager.instance.xiangmu_ceshi_kaiguan = !1), ailin_sdk_manager.addBossTitle("开启调试"))
//             : this.node_scroll_view_content.removeAllChildren();
//     },
//     update: function () {
//         if (this.node_m_node.active) {
//             this.node.scale = Math.min(cc.winSize.width / cc.Canvas.instance.designResolution.width, 1);
//         }
//     }
// });

cc.Class({
    extends: cc.Component,
    properties: {
        node_boss: cc.Node,
        clear_count: 0,
        node_m_node: cc.Node
    },

    /** 
     * 处理滚动视图触摸结束事件 
     * @param {cc.Event.EventTouch} event 
     */
    handle_event_scrollview_touch_end(event) {
        this.node_scroll_view_content.y += event.getDelta().y;
        const minY = -400 - (this.node_scroll_view_content.height - 400);
        if (this.node_scroll_view_content.y < minY) {
            this.node_scroll_view_content.y = minY;
        }
        if (this.node_scroll_view_content.y > -400) {
            this.node_scroll_view_content.y = -400;
        }
    },

    /** 初始化组件 */
    onLoad() {
        this.node_m_node = cc.find("node/node", this.node);
        this.node_scroll_view_content = cc.find("node/node/ScrollView/view/content", this.node);
        this.scrollView = cc.find("node/node/ScrollView", this.node);

        this.scrollView.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
            this.node_scroll_view_content.y += event.getDelta().y;
        });

        this.scrollView.on(cc.Node.EventType.TOUCH_END, this.handle_event_scrollview_touch_end.bind(this));
        this.scrollView.on(cc.Node.EventType.TOUCH_CANCEL, this.handle_event_scrollview_touch_end.bind(this));
        this.scrollView._touchListener.setSwallowTouches(false);

        this.titleArray = [];

        const widget = this.node_boss.addComponent(cc.Widget);
        widget.left = 0;
        widget.top = 0;
        widget.isAlignTop = true;
        widget.isAlignLeft = true;
    },

    /** 开始 */
    start() {
        this.touchNum = 0;
        this.time = Math.floor(Date.now() / 1000);

        this.node_boss.on(cc.Node.EventType.TOUCH_START, function () {
            if (this.node_boss._touchListener) {
                this.node_boss._touchListener.setSwallowTouches(false);
            }
            this.touchNum++;
            const currentTime = Math.floor(Date.now() / 1000);

            if (currentTime - this.time < 10) {
                if (this.touchNum >= 7) {
                    cc.systemEvent.emit("lieyou_openBossKey");
                    al_show_debug = true;
                    cc.find("node/node/version", this.node).getComponent(cc.Label).string =
                        " " + _sdk_version + "/" + ailin_sdk_manager.instance.getVersion();
                    this.touchNum = 0;
                    this.time = currentTime;
                    cc.find("node/node", this.node).active = true;
                    ailin_sdk_manager.setClipboardData(
                        JSON.stringify({
                            uuid: AL_User_Info.huoqu_open_id(),
                            openid: AL_User_Info.huoqu_open_id()
                        })
                    );
                    ailin_sdk_manager.showToast("成功复制uuid");
                    ailin_sdk_manager.addBossTitle("后台：" + al_login_url);
                    ailin_sdk_manager.instance.xiangmu_ceshi_kaiguan = false;
                }
            } else {
                this.touchNum = 0;
                this.time = currentTime;
            }
        }, this);
    },

    /**
     * 添加标题
     * @param {string} title 标题内容
     * @param {cc.Color} color 标题颜色
     */
    tianjiaTitle(title = "", color) {
        if (cc.find("node/node", this.node).active) {
            const contentNode = this.node_scroll_view_content;
            const titleNode = new cc.Node();
            titleNode.width = 300;
            titleNode.anchorX = 0;
            titleNode.anchorY = 0;
            const labelComponent = titleNode.addComponent(cc.Label);
            labelComponent.overflow = cc.Label.Overflow.RESIZE_HEIGHT;
            labelComponent.string = title;
            labelComponent.fontSize = 25;
            contentNode.addChild(titleNode);
            titleNode.color = color;
        }
    },

    /** 关闭回调 */
    guanbiHuidiao() {
        cc.find("node/node", this.node).active = false;
    },

    /** 检查回调 */
    jianchaHuidiao() {
        const onlineParam = ailin_sdk_manager.instance._lieyou_online_param;
        if (onlineParam) {
            const paramStr = JSON.stringify(onlineParam);
            AL_Framework_al_interface.xianshi_layer_ceng(paramStr);
        }
    },

    /** 清除回调 */
    qingchuHuidiao() {
        this.clear_count++;
        setTimeout(() => {
            this.clear_count--;
        }, 900);

        console.log("--------------qingchuHuidiao  clear_count", this.clear_count);

        if (this.clear_count >= 6) {
            ailin_sdk_manager.instance.xiangmu_ceshi_kaiguan = false;
            ailin_sdk_manager.addBossTitle("开启调试");
        } else {
            this.node_scroll_view_content.removeAllChildren();
        }
    },

    /** 更新逻辑 */
    update() {
        if (this.node_m_node.active) {
            this.node.scale = Math.min(cc.winSize.width / cc.Canvas.instance.designResolution.width, 1);
        }
    }
});
